from django.db import models


# class OperationType(models.Model):
#     '''
#     操作分类
#     '''
#     name = models.CharField(max_length=20, verbose_name='操作类型')
#
#     class Meta:
#         verbose_name = '操作分类'
#         verbose_name_plural = '操作分类'
#
#     def __str__(self):
#         return self.name


class OperationHistory(models.Model):
    '''
    台站操作历史
    '''
    # NEW = 'new'
    # MIGRATE = 'migrate'
    # REMOVAL = 'removal'
    # PATROL = 'patrol'
    # MAINTAIN = 'maintain'
    #
    # OPERATION_TYPE = (
    #     (NEW, '新建'),
    #     (REMOVAL, '撤除'),
    #     (PATROL, '查台'),
    #     (MAINTAIN, '维护'),
    # )

    station = models.ForeignKey('seisnet.Station', null=True, blank=True, on_delete=models.CASCADE)
    operation_type = models.CharField(max_length=100, verbose_name='操作类型')
    is_last = models.BooleanField(default=True, verbose_name='是否是最新列表')


class OperationAction(models.Model):
    '''
    台站操作动作
    '''
    opertion_history = models.ForeignKey('OperationHistory', on_delete=models.CASCADE, null=True, blank=True)
    opertion_object_A = models.CharField(max_length=100, verbose_name='操作对象A', null=True, blank=True)
    opertion_object_B = models.CharField(max_length=100, verbose_name='操作对象B', null=True, blank=True)
    opertional_action = models.CharField(max_length=200, verbose_name='操作动作')

    station = models.ForeignKey('seisnet.Station', on_delete=models.CASCADE, verbose_name='所属台站')


class StationStatus(models.Model):
    '''
    查台状态
    '''
    NORMAL = 'NM'
    OUTAGE = 'OA'
    MINOR_FAILURE = 'MF'
    OTHER = 'OT'

    WORK_STATUS_TYPE = (
        (NORMAL, '正常'),
        (OUTAGE, '宕机'),
        (MINOR_FAILURE, '小故障'),
        (OTHER, '其它')
    )

    NORMAL_SAMPLING = 'NMS'
    STOP_SAMPLING = 'STS'
    INTERRUPTED = 'ITR'

    DATA_STATUS_TYPE = (
        (NORMAL_SAMPLING, '正常采样'),
        (STOP_SAMPLING, '采样停止'),
        (INTERRUPTED, '采样不连续'),
        (OTHER, '其它')
    )

    CONTINUOUS = 'CTO'
    SLEEPING = 'SLP'

    GPS_STATUS_TYPE = (
        (CONTINUOUS, '连续'),
        (SLEEPING, '睡眠'),
        (OTHER, '其它')
    )

    BEFORE_OPERATION = 'BO'
    AFTER_OPERATION = 'AO'

    AB_STATUS_TYPE = (
        (BEFORE_OPERATION, '操作之前'),
        (AFTER_OPERATION, '操作之后')
    )

    station = models.ForeignKey('seisnet.Station', on_delete=models.CASCADE)
    patrol_datetime = models.DateTimeField(verbose_name='查台时间')
    work_status = models.CharField(max_length=10, choices=WORK_STATUS_TYPE, default=NORMAL, verbose_name='工作状态')
    data_status = models.CharField(max_length=10, choices=DATA_STATUS_TYPE, default=NORMAL_SAMPLING,
                                   verbose_name='数据采样状态')
    gps_status = models.CharField(max_length=10, choices=GPS_STATUS_TYPE, default=CONTINUOUS, verbose_name='gps状态')
    gps_stars = models.PositiveSmallIntegerField(verbose_name='gps搜星数')
    voltage = models.FloatField(verbose_name='输入电压')
    backup_voltage = models.FloatField(null=True, blank=True, verbose_name='备份电压')
    centroid_postion = models.CharField(max_length=20, null=True, blank=True, verbose_name='质心位置')
    is_zeroing = models.BooleanField(default=False, verbose_name='是否调零')
    card1_storage = models.FloatField(default=0, null=True, blank=True, verbose_name='存储卡1已存储(Mb)')
    card2_storage = models.FloatField(default=0, null=True, blank=True, verbose_name='存储卡2已存储(Mb)')
    card1_total = models.FloatField(default=0, null=True, blank=True, verbose_name='存储卡1总容量(Mb)')
    card2_total = models.FloatField(default=0, null=True, blank=True, verbose_name='存储卡2总容量(Mb)')
    description = models.TextField()
    is_last = models.BooleanField(default=True, verbose_name='是否是最新状态')
    op_ab_status = models.CharField(max_length=10, choices=AB_STATUS_TYPE, default=BEFORE_OPERATION,
                                    verbose_name='操作前后的状态')
